import BaySik
import bge
#logic = bge.logic
#cont = logic.getCurrentController()
#own = cont.owner

# KEYBOARD SENSOR# 
###################################### 

def keyInput(senKBoard, strKey, intAct):
    """
    senKBoard should be the name of the keyboard sensor
    This looks up the given key in the above module an returns
    a bool showing if it is in the keys currently pressed.
    intActuses a number to tell key status 1 = down, 2 = held, 3 = up
    """
    cont = bge.logic.getCurrentController()
    # Returns false if there is a problem
    retVal = False
    # make sure the sensor is there, why am I not checking dir() for events?
    # 2am, that's why
    if(senKBoard in cont.sensors):
        # get the sensor
        kBoard = cont.sensors[senKBoard]
        #print(dir(kBoard))
        #backtrace the keynum, or return false, false is good
        keynum = BaySik.keyToNum(strKey)
        if(keynum != False):
            # somehow this will pose an error if the user doesn't use a keybord
            # sensor, and I fear the user is moonmoon
            if([keynum, intAct] in kBoard.events):
                retVal = True
        else: # yep, moonmoon
            print("Error: possible wrong key string value, check keyToNum for accepted values")
    else:#who invited moonmoon
        print("Error: Please check value given for senKBoard in keyInput module, or check for sensor")
        
    return retVal # return true/false
    




    

#END KEYBOARD SENSOR# 
###################################### 

#HITTING SENSORS#
###################################
# no longer called fisticuffs, but thanks to the 'internet'
# I now know what they are called now


#hitMat, hitObj :
#ray, radar, near, collision
#hitPos, hitNorm :
#ray, mouseover*(has hitobj)
# hitobjlist :
#radar, near, collision
def rncObjectList(strSen):# this one was last
    """
    Only works with radar, near, and collision, returns object list
    And this marks ver. 0.25
    """
    cont = bge.logic.getCurrentController()
    # they all work the same, setup return value,
    # check if sensor is legit, return value based on input
    # fuss at user if they forget anything.
    # really, I like knowing when I forgot something, usually punctuation
    hit = False
    sensor = cont.sensors[strSen]
    if("hitObjectList" in dir(sensor)):
        if(sensor.positive):
            hit = sensor.hitObjectList
        return hit
    else:
        print("Error: rncObjectList Only works with radar, near, and collision sensors")
        
# ray and mouseover share a lot of things, but not hitMaterial
def rayAndMouseOver(strSen, intColType):
    """
    Since mouseover does not have hitMaterial, and shares functions
    with ray, I'll combine them a bit.
    0 = hitpos, 1 = hitobj, other = hitnormal
    """
    cont = bge.logic.getCurrentController()
    hit = False
    sensor = cont.sensors[strSen]
    if("hitPosition" in dir(sensor) and "hitObject" in dir(sensor) and "hitNormal" in dir(sensor) ):
        if(sensor.positive):
            if(intColType == 0):
                hit = sensor.hitPosition
            elif(intColType == 1):
                hit = sensor.hitObject
            else:
                hit = sensor.hitNormal
        return hit
    else:
        print("Error: rayAndMouseOver either sensor is not a mouseover, or ray")
        print("remember to check mouse event")
        
        
# yes, I know, redundancy, but it should cover these sensors well.
# five sensors, three modules, and one bed.
def hitMatOrObj(strSen, booMOO):
    """
    Works for ray, radar, near and collision sensors
    returns material or object (false if nothing is happening)
    """
    cont = bge.logic.getCurrentController()
    hit = False
    sensor = cont.sensors[strSen]
    if("hitMaterial" in dir(sensor) and "hitObject" in dir(sensor) ):
        if(sensor.positive):
            if(booMOO == False):
                hit = sensor.hitMaterial
            elif(booMOO == True):
                hit = sensor.hitObject
        return hit
    else:
        print("Error: hitMatOrObj works for ray, radar, near and collision sensors")

def getSensor(strSen):
    cont = bge.logic.getCurrentController()
    sensor = cont.sensors[strSen]
    #print(dir(sensor))


#END HITTING SENSORS#
###################################